﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using System.ComponentModel;

namespace HugeFlow.OOB.Behaviors
{
    public class OOBIntallBehavior : Behavior<Button>
    {
        protected override void OnAttached()
        {
            base.OnAttached();

            // OOB이면 버튼을 감춘다
            if (Application.Current.IsRunningOutOfBrowser == true)
            {
                AssociatedObject.Visibility = Visibility.Collapsed;
                return;
            }

            AssociatedObject.Click += new RoutedEventHandler(AssociatedObject_Click);
        }

        void AssociatedObject_Click(object sender, RoutedEventArgs e)
        {
            if (Application.Current.InstallState == InstallState.NotInstalled)
            {
                Application.Current.Install();
            }
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();

            AssociatedObject.Click -= new RoutedEventHandler(AssociatedObject_Click);
        }
    }
}
